<template>
    <div>
      <!-- 面包屑导航 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- 卡片视图区 -->
      <el-card>
        <!-- 搜索区 -->
        <el-row>
          <el-col :span="8">
            <el-input placeholder="请输入内容">
              <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input>
          </el-col>
        </el-row>
        <!-- 订单列表区 -->
        <el-table :data="orderList" stripe border style="width: 100%">
          <el-table-column label="序号" type="index" width="50"></el-table-column>
          <el-table-column prop="order_number" label="订单编号" width="280px"></el-table-column>
          <el-table-column prop="order_price" label="订单价格"></el-table-column>
          <el-table-column label="是否付款">
            <template slot-scope="scope">
              <el-tag type="danger" v-if="scope.row.pay_status === '0'">未付款</el-tag>
              <el-tag type="success" v-else>已付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="is_send" label="是否发货"></el-table-column>
          <el-table-column  label="下单时间">
            <template slot-scope="scope">
              {{scope.row.create_time | dateFormat}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="220px">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" icon="el-icon-edit" @click="showBox(scope.row.order_id)"></el-button>
              <el-button type="success" size="mini" icon="el-icon-location"></el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页区 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[5, 10, 20, 50]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
        <!-- 修改对话框 -->
        <el-dialog title="修改地址" width="50%" :visible.sync="editDialogVisible" @close="addressDialogClosed">
          <el-form :model="addressForm" :rules="addressFormRules" ref="addressFormRef" label-width="100px">
            <el-form-item label="省市区/县：" prop="address1">
              <el-cascader
                v-model="addressForm.address1"
                :options="cityData" :props="{ expandTrigger: 'hover' }">
              </el-cascader>
            </el-form-item>
            <el-form-item label="详细地址：" prop="address2">
              <el-input v-model="addressForm.address2"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="editDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
          </span>
        </el-dialog>
        <!-- 物流显示框 -->
        <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
          <span>这是一段信息</span>
        </el-dialog>
      </el-card>
    </div>
</template>

<script>
import citydata from './citydata'
export default {
  name: 'orders',
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      /* 订单总数 */
      total: 0,
      /* 订单数据 */
      orderList: [],
      /* 修改对话框 */
      editDialogVisible: false,
      /* 修改订单地址 */
      addressForm: {
        address1: [],
        address2: ''
      },
      /* 修改订单 校验规则 */
      addressFormRules: {
        address1: [{ required: true, message: '请填写正确的地址', trigger: 'blur' }],
        address2: [{ required: true, message: '请填写正确的地址', trigger: 'blur' }]
      },
      /* 导入的地址名 */
      cityData: citydata,
      /* 物流显示框 */
      progressVisible: false,
      /* 物流信息 */
      progressInfo: []
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    /* 获取订单列表 */
    async getOrderList () {
      const { data: res } = await this.$http.get('/orders', { params: this.queryInfo })
      if (res.meta.status !== 200) {
        return this.$message.error('订单数据获取失败！')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
      console.log(this.orderList)
      console.log(this.total)
    },
    /* 监听 pageSize大小变化 */
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    /* 监听当前页改变 触发事件 */
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    },
    /* 修改对话框 */
    showBox (id) {
      this.editDialogVisible = true
    },
    /* 修改对话框关闭 触发 */
    addressDialogClosed () {
      this.$refs.addressFormRef.resetFields()
    },
    /* 追踪物流进度 */
    async showProgressBox () {
      const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      if (res.meta.status !== 200) {
        return this.$message.error('物流信息获取失败')
      }
      this.progressInfo = res.data
      this.progressVisible = true
      console.log(res.data)
    }
  }
}
</script>

<style lang="less" scoped>

</style>
